package mathsTrainingSystem;

import mathsTrainingSystem.ErrorRecords.ErrorRecorder;
import java.util.Scanner;

public class ErrorTraining {
	
	public static void modifyErrorRecorder(ErrorRecords errorRecords, int index, int a, int b, int c, int flag, int tag, int asw) {  
        ErrorRecorder recorder = errorRecords.getErrorRecorder(index);  
        if (recorder != null) {  
            recorder.a = a;
            recorder.b = b;
            recorder.c = c;
            recorder.flag = flag;
            recorder.tag = tag;
            recorder.asw = asw;
        }  
    } 

	public static void zeroLize(ErrorRecords errorRecords) {
		for(int i = 0; i <= 20; i++) {
	        modifyErrorRecorder(errorRecords, i, 0, 0, 0, 0, 0, 0);
		}
	}
	
	public static void accessErrorRecorder(ErrorRecords errorRecords, int i) {  
        ErrorRecorder recorder = errorRecords.getErrorRecorder(i);  
        if (recorder != null) {  
            if (recorder.flag != 0) {
            	Judge(recorder.a, recorder.b, recorder.c, recorder.flag, recorder.tag, recorder.asw);
            }
        }  
    } 
	
	//tag = 0表示c不存在；tag = 1表示c存在
	//flag = 0表示数组未赋值;tag = 0,flag = 1表示加法;tag = 0,flag = 2表示减法;tag = 0,flag = 3表示乘法;tag = 0,flag = 4表示除法
	//tag = 1,flag = 1表示加加;tag = 1,flag = 2表示加减;tag = 1,flag = 3表示减加;tag = 1,flag = 4表示减减;tag = 1,flag = 5表示带余数的除法
	
	public static void Judge(int a, int b, int c, int flag, int tag, int asw) {
		Scanner scanner = new Scanner(System.in);
		int userasw;
		if(tag == 0) {
			switch(flag) {
			case 1:
				System.out.println(a + "+" + b + "=");
				break;
			case 2:
				System.out.println(a + "-" + b + "=");
				break;
			case 3:
				System.out.println(a + "x" + b + "=");
				break;
			case 4:
				System.out.println(a + "÷" + b + "=");
				break;
			}
		}
		if(tag == 1) {
			switch(flag) {
			case 1:
				System.out.println(a + "+" + b + "+" + c + "=");
				break;
			case 2:
				System.out.println(a + "+" + b + "-" + c + "=");
				break;
			case 3:
				System.out.println(a + "-" + b + "+" + c + "=");
				break;
			case 4:
				System.out.println(a + "-" + b + "-" + c + "=");
				break;
			case 5:
				System.out.println(a + "÷" + b + "=");
				break;
			}
		}
		while(true) {
			while (!scanner.hasNextInt()) {  
	            System.out.println("输入无效，请重新输入一个整数: ");  
	            scanner.next();
	        }
			userasw = scanner.nextInt();
			if(userasw == asw) {
				System.out.println("回答正确！\n");
				if(flag == 5) {
					System.out.println("请输入余数：\n");  
					int remainder;
					while (!scanner.hasNextInt()) {  
			            System.out.println("输入无效，请重新输入一个整数: ");  
			            scanner.next();
			        }
					remainder = scanner.nextInt();
					while(true) {
						if(remainder == c) {
							System.out.println("回答正确！\n");
							break;
						}
						else {
							System.out.println("回答错误！请重新回答\n");
						}
					}
				}
				break;
			}
			else {
				System.out.println("回答错误！请重新回答\n");
			}
		}
	}
}
